<template>
  <div class="container">
    <el-form
      :inline="true"
      :model="vmform1"
      ref="vmform1"
      class="demo-form-inline"
    >
      <el-form-item label="设备编号">
        <el-input v-model="vmform1.innerCode" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="search"
          >查询</el-button
        >
      </el-form-item>
    </el-form>
    <div class="app-container">
      <el-table ref="multipleTable" tooltip-effect="dark" :data="VmList">
        <!-- 放置列 -->
        <el-table-column
          prop="index"
          align="center"
          width="50px"
          label="序号"
        />
        <el-table-column prop="innerCode" align="center" label="设备编号" />
        <el-table-column
          prop="type.name"
          align="center"
          label="设备型号"
          width="75px"
        />
        <el-table-column align="center" label="详细地址">
          <template v-slot="{ row }">
            {{ row.node.addr.split("-").pop() }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="运营状态" width="65px">
          <template v-slot="{ row }">
            <span v-if="row.vmStatus == 0">未投放</span>
            <span v-if="row.vmStatus == 1">运营</span>
            <span v-if="row.vmStatus == 2">维修</span>
            <span v-if="row.vmStatus == 3">撤机</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="设备状态">
          <template v-slot="{ row }">
            <span class="span1" v-if="!row.status[10001]">离线</span
            ><span class="span1" v-else>在线</span>
            <span class="span2" v-if="row.status[10002]">运营</span>
            <span class="span2" v-if="row.status[10003]">传动轴</span>
          </template>
        </el-table-column>
        <el-table-column align="center" width="100px" label="操作">
          <template v-slot="{ row }">
            <!-- 放置操作按钮 -->
            <el-button size="mini" type="text" @click="details(row)"
              >查看详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 放置分页组件 -->
      <el-row
        type="flex"
        style="height: 60px"
        align="middle"
        justify="space-between"
      >
        <el-col :span="12"
          ><span style="font-size: 13px; color: #999; padding-left: 12px"
            >共{{ totalcount }}条记录 第{{ pageParams.pageIndex }}/{{
              totalpage
            }}页</span
          ></el-col
        >
        <el-col :push="12">
          <el-button-group>
            <el-button
              type="primary"
              @click="innPage"
              size="mini"
              :disabled="pageParams.pageIndex == 1"
              icon="el-icon-arrow-left"
              style="
                background-color: #d5ddf8;
                color: #000;
                margin-right: 12px;
                border: none;
              "
              >上一页</el-button
            >
            <el-button
              type="primary"
              @click="addPage"
              size="mini"
              :disabled="pageParams.pageIndex == this.totalpage"
              style="background-color: #d5ddf8; color: #000; border: none"
              >下一页<i class="el-icon-arrow-right el-icon--right"></i
            ></el-button>
          </el-button-group>
        </el-col>
      </el-row>
    </div>
    <!-- 设备详情的dialog -->
    <el-dialog
      :visible="showProductDialog"
      title="商品展示"
      width="700px"
      @close="closefn"
    >
      <el-row
        class="header"
        type="flex"
        align="middle"
        justify="space-between"
        style="background-color: #f3f6fb; height: 45px; margin-top: -20px"
      >
        <el-col>
          <span style="margin-left: 15px"
            >销售量:<span style="color: #0a7bcd">{{ showNum }} 个</span></span
          >
        </el-col>
        <el-col>
          <span style="margin-left: 15px"
            >销售额:<span style="color: #0a7bcd"
              >{{ showMoney }} 万元</span
            ></span
          >
        </el-col>
        <el-col>
          <span style="margin-left: 15px"
            >补货次数:<span style="color: #0a7bcd"> 0 次</span></span
          >
        </el-col>
        <el-col>
          <span style="margin-left: 15px"
            >维修次数:<span style="color: #0a7bcd"> 0 次</span></span
          >
        </el-col>
      </el-row>
      <div>
        <span style="display:block;margin:15px 0">商品销量（月）</span>
        <div  >
          <div v-if="skuCollect.length" class="singlegrid">
            <div class="grid" v-for="(item, index) in skuCollect" :key="index">
              {{ item.skuName }}:{{ item.count }}
            </div>
          </div>
          <div v-else style="margin-top:35px; display: flex;
    justify-content: center;
    align-items: center;">该设备暂未使用</div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getShowNum,
  getShowMoney,
  getRepairNum,
  getSkuCollect,
  getAddNum,
  getVmList,
} from "@/api/mechian";
import { start } from "nprogress";
export default {
  data() {
    return {
      showProductDialog: false,
      showNum: "",
      showMoney: "",
      repairNum: "",
      addNum: "",
      skuCollect: [],
      VmList: [], //首页table 设备数组
      totalcount: "",
      totalpage: "",
      pageParams: {
        pageIndex: 1,
        pageSize: 10,
      },
      vmform1: {
        innerCode: "", //根据设备号查询
      },
    };
  },
  created() {
    this.getVmList();
  },
  computed: {
    // start() {
    //   return this.$moment().format("YYYY-MM-01 00:00:00");
    // },
    // end() {
    //   return this.$moment().format("YYYY-MM-DD 23:59:59");
    // },
    // start1() {
    //   return this.$moment().format("YYYY-MM-01");
    // },
    // end1() {
    //   return this.$moment().format("YYYY-MM-DD");
    // },
  },
  methods: {
    closefn() {
      this.showProductDialog = false;
    },
    async getVmList() {
      const res = await getVmList(
        this.pageParams.pageIndex,
        this.pageParams.pageSize,
        this.vmform1.innerCode
      );
      // console.log(res);
      this.VmList = res.currentPageRecords;
      this.totalpage = res.totalPage;
      this.totalcount = res.totalCount;
      this.VmList.forEach((item, index) => {
        this.$set(
          item,
          "index",
          this.pageParams.pageSize * (this.pageParams.pageIndex - 1) + index + 1
        );
      });
    },
    search() {
      this.pageParams.pageIndex = 1;
      this.getVmList();
    },
    //下一页
    addPage() {
      this.pageParams.pageIndex++;
      this.getVmList();
    },
    // 上一页
    innPage() {
      this.pageParams.pageIndex--;
      this.getVmList();
    },
    async details(row) {
      console.log(row);
      const start = this.$moment().format("YYYY-MM-01 00:00:00");
      const end = this.$moment().format("YYYY-MM-DD 23:59:59");
      const start1 = this.$moment().format("YYYY-MM-01");
      const end1 = this.$moment().format("YYYY-MM-DD");
      const res = await getShowNum(start, end, row.innerCode);
      this.showNum = res;
      const res1 = await getShowMoney(start, end, row.innerCode);
      this.showMoney = (res1 / 1000000).toFixed(2);
      const res3 = await getSkuCollect(row.innerCode, start1, end1);
      this.skuCollect = res3;
      this.showProductDialog = true;
      //   const res4 =  await getAddNum(row.innerCode,start1,end1);
      //  this.addNum=res4
      //    const res2 =   await getRepairNum(row.innerCode,start1,end1)
      //  this.repairNum=res2
    },
  },
};
</script>

<style lang="scss" scoped>
.role-operate {
  padding: 10px;
}
::v-deep .el-dialog {
  border-radius: 10px;
  padding: 20px;
  width: 50%;
  .dialog-footer {
    margin-top: -30px;
  }
  .area {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
  }
  .title {
    width: 50%;
    margin-bottom: 20px;
    .right {
      margin-left: 10px;
    }
  }
}
.policybutton {
  display: flex;
  height: 40px;
  margin-top: 15px;
  align-items: center;
  justify-content: center;
}
.my-select {
  width: 350px;
}

.span1 {
  margin: 0 2px;
  padding: 0 6px;
  border-radius: 6px;
  color: #fff;
  background-color: #ffb92f;
}
.span2 {
  margin: 0 2px;
  border-radius: 6px;
  padding: 0 6px;
  color: #fff;
  background-color: #b8d698;
}
.singlegrid {
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  .grid {
    width: 25%;
    height: 30px;
    padding: 3px 0;
    border: 1px solid rgb(92, 88, 88);
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>
>
